﻿using System.Text;
using Fluffy.Library.FileSources;
using System.IO;

namespace Fluffy.Text
{
	internal class TextDocumentModel
	{
		private readonly IFile _file;

		public TextDocumentModel(IFile file)
		{
			_file = file;
		}

		public string GetText(Encoding encoding)
		{
			if (IsNewFile) 
				return string.Empty;

			return File.ReadAllText(_file.FilePath, encoding);
		}

		public bool IsNewFile
		{
			get { return _file is NewFile; }
		}

		public string FomatExtension
		{
			get
			{
				if (_file is LocalFile)
					return Path.GetExtension(_file.FilePath);

				return string.Empty;
			}
		}

		public void SaveText(string text)
		{
			File.WriteAllText(_file.FilePath, text);
		}

		public void SaveTextAs(string path, string text)
		{
			File.WriteAllText(path, text);
		}
	}
}
